package o2o.web.actions.shop;

import com.jinyou.utils.common.ValidateUtil;
import o2o.cache.shop.ShopTipMemory;
import o2o.cache.shop.ShopTipRelationMemory;
import o2o.dao.PO.shop.ShopTip;

import java.util.ArrayList;
import java.util.List;

public class ShopTipMan {

    //根据店铺获取标签列表
    public static List<ShopTip> tipListOfShopId(Long shopId) {
        if (ValidateUtil.isNotID(shopId)) {
            return null;
        }

        List<Long> idList = ShopTipRelationMemory.getInstance().getTipListByShopId(shopId);
        if (ValidateUtil.isAbsList(idList)) {
            return convertToShopTip(idList);
        }

        return null;
    }


    //根据代理获取标签列表
    public static List<ShopTip> tipListOfAgentId(Long agentId) {
        if (ValidateUtil.isNotID(agentId)) {
            return null;
        }

        List<Long> idList = ShopTipRelationMemory.getInstance().getTipListByAgentId(agentId);
        if (ValidateUtil.isAbsList(idList)) {
            return convertToShopTip(idList);
        }

        return null;
    }

    //-------------------------------------
    private static List<ShopTip> convertToShopTip(List<Long> tipIdList){
        if (ValidateUtil.isAbsList(tipIdList)) {
            List<ShopTip> list = new ArrayList<>();
            for (int i = 0; i < tipIdList.size(); i++) {
                if (ValidateUtil.isNotID(tipIdList.get(i))) {
                    continue;
                }
                ShopTip info = ShopTipMemory.getInstance().getById(tipIdList.get(i));
                if (null == info) {
                    continue;
                }
                list.add(info);
            }
            return list;
        }

        return null;
    }
}
